<template>
    <div class="login-container">
        <video class="video" muted src="../../assets/video/1.mp4"></video>
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <h2>员工管理</h2>
            <el-form-item label="用户名" prop="username">
                <el-input type="usernameword" v-model="ruleForm.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="checkusername">
                <el-input type="usernameword" v-model="ruleForm.checkusername" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="age">
                <el-input v-model.number="ruleForm.age"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button class="submit" type="primary" @click="submitForm('ruleForm')">提交</el-button>
            </el-form-item>
        </el-form>

    </div>
</template>
<script>
//callback只要传参了,表示表单验证不通过,不传参表示表单验证通过
//value就是在input中的输入值
// 验证码
var validateCaptcha=(rule,value,callback)=>{
 if(value.length!==5){
    callback('验证码必须是5位');
 }else{
    callback();
 }
};
// 用户名
var validateUsername=(rule,value,callback)=>{
    var reg = /^\w{3,16}$/;
    if(reg.test(value)){
        callback();
    }else{
        callback('用户名需是字母数字下划线,3-16位');
    }
};
var validateusername = (rule, value, callback) => {
	if (value.length < 3) {
		callback("密码长度不能小于3位");
	} else {
		callback();
	}
};
export default {
   
    data() {
        return {
            ruleForm: {
                username: '',
                checkusername: '',
                age: ''
            },
            rules: {
                username: [
                    { validator: validateUsername, trigger: 'blur' }
                ],
                checkusername: [
                    { validator: validateusername, trigger: 'blur' }
                ],
                age: [
                    { validator: validateCaptcha, trigger: 'blur' }
                ]
            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
    }
}
</script>
<style lang="less" scoped>
.video {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;

}

.login-container {
    position: fixed;
    right: 2%;
    top: 25%;
    border-radius: 5px;
    width: 360px;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 20px 0 50px 0;
    .submit{
        width: 250px;
    }
}

h2 {
    text-align: center;
    color: #fff;
}

.el-input {
    width: 250px;
}
</style>
   
